home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / ab20_archive / text / cmanual.lzh / ACM2.lzh / Menus / Example6.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  20KB  |  524 lines

  1. /* Example6                                                              */
  2. /* This program opens a normal window to which we connect a menu strip.  */
  3. /* The menu consists of six small dices which are all action items. This */
  4. /* example shows how you can use Images inside a menu.                   */
  5.  
  6.  
  7.  
  8. #include <intuition/intuition.h>
  9.  
  10.  
  11.  
  12. struct IntuitionBase *IntuitionBase;
  13.  
  14.  
  15.  
  16. /*************************************************************************/
  17. /*                             D I C E   1                               */
  18. /*************************************************************************/
  19.  
  20. /* Data for dice 1: */
  21. USHORT chip dice1_data[]=
  22. {
  23.   0x0000,  /* 0000 0000 0000 0000   0 : Black  */
  24.   0x0000,  /* 0000 0000 0000 0000   1 : Orange */
  25.   0x0000,  /* 0000 0000 0000 0000              */
  26.   0x03C0,  /* 0000 0011 1100 0000              */
  27.   0x03C0,  /* 0000 0011 1100 0000              */
  28.   0x0000,  /* 0000 0000 0000 0000              */
  29.   0x0000,  /* 0000 0000 0000 0000              */
  30.   0x0000   /* 0000 0000 0000 0000              */
  31. };
  32.  
  33. /* Image structure for dice 1: */
  34. struct Image dice1=
  35. {
  36.   0,          /* LeftEdge, 0 pixels out. */
  37.   0,          /* TopEdge, 0 pixels down. */
  38.   16,         /* Width, 16 pixels wide. */
  39.   8,          /* Height, 8 lines heigh. */
  40.   1,          /* Depth, one Bitplane. */
  41.   dice1_data, /* ImageData, pointer to the image data. */
  42.   0x1,        /* PlanePick, affect Bitplane zero. */
  43.   0x2,        /* PlaneOnOff, fill Bitplane one with 1's. */
  44.   NULL        /* NextImage, no Image structure connected to this one. */
  45. };
  46.  
  47. /* The MenuItem structure for dice 1: */
  48. struct MenuItem my_dice1_item=
  49. {
  50.   NULL,            /* NextItem, this is the last item in the list. */
  51.   0,               /* LeftEdge, 0 pixels out. */
  52.   50,              /* TopEdge, 50 lines down. */
  53.   50,              /* Width, 50 pixels wide. */
  54.   8,               /* Height, 8 lines high. */
  55.   ITEMENABLED|     /* Flags, this item will be enabled. */
  56.                    /*        render this item with an Image. */
  57.                    /*        (ITEMTEXT is not set.) */
  58.                    /*        it is an action item. */
  59.                    /*        (CHECKIT is not set.) */
  60.   HIGHCOMP,        /*        complement the colours when highlihted. */
  61.   0x00000000,      /* MutualExclude, no mutualexclude. */
  62.   (APTR) &dice1,   /* ItemFill, pointer to the image. */
  63.   NULL,            /* SelectFill, nothing since we complement the col. */
  64.   0,               /* Command, no command-key sequence. */
  65.   NULL,            /* SubItem, no subitem list. */
  66.   MENUNULL,        /* NextSelect, no items selected. */
  67. };
  68.  
  69.  
  70.  
  71. /*************************************************************************/
  72. /*                             D I C E   2                               */
  73. /*************************************************************************/
  74.  
  75. /* Data for dice 2: */
  76. USHORT chip dice2_data[]=
  77. {
  78.   0x0000,  /* 0000 0000 0000 0000   0 : Black  */
  79.   0x7800,  /* 0111 1000 0000 0000   1 : Orange */
  80.   0x7800,  /* 0111 1000 0000 0000              */
  81.   0x0000,  /* 0000 0000 0000 0000              */
  82.   0x0000,  /* 0000 0000 0000 0000              */
  83.   0x001E,  /* 0000 0000 0001 1110              */
  84.   0x001E,  /* 0000 0000 0001 1110              */
  85.   0x0000   /* 0000 0000 0000 0000              */
  86. };
  87.  
  88. /* Image structure for dice 2: */
  89. struct Image dice2=
  90. {
  91.   0,          /* LeftEdge, 0 pixels out. */
  92.   0,          /* TopEdge, 0 pixels down. */
  93.   16,         /* Width, 16 pixels wide. */
  94.   8,          /* Height, 8 lines heigh. */
  95.   1,          /* Depth, one Bitplane. */
  96.   dice2_data, /* ImageData, pointer to the image data. */
  97.   0x1,        /* PlanePick, affect Bitplane zero. */
  98.   0x2,        /* PlaneOnOff, fill Bitplane one with 1's. */
  99.   NULL        /* NextImage, no Image structure connected to this one. */
  100. };
  101.  
  102. /* The MenuItem structure for dice 2: */
  103. struct MenuItem my_dice2_item=
  104. {
  105.   &my_dice1_item,  /* NextItem, pointer to the next item in the list. */
  106.   0,               /* LeftEdge, 0 pixels out. */
  107.   40,              /* TopEdge, 40 lines down. */
  108.   50,              /* Width, 50 pixels wide. */
  109.   8,               /* Height, 8 lines high. */
  110.   ITEMENABLED|     /* Flags, this item will be enabled. */
  111.                    /*        render this item with an Image. */
  112.                    /*        (ITEMTEXT is not set.) */
  113.                    /*        it is an action item. */
  114.                    /*        (CHECKIT is not set.) */
  115.   HIGHCOMP,        /*        complement the colours when highlihted. */
  116.   0x00000000,      /* MutualExclude, no mutualexclude. */
  117.   (APTR) &dice2,   /* ItemFill, pointer to the image. */
  118.   NULL,            /* SelectFill, nothing since we complement the col. */
  119.   0,               /* Command, no command-key sequence. */
  120.   NULL,            /* SubItem, no subitem list. */
  121.   MENUNULL,        /* NextSelect, no items selected. */
  122. };
  123.  
  124.  
  125.  
  126. /*************************************************************************/
  127. /*                             D I C E   3                               */
  128. /*************************************************************************/
  129.  
  130. /* Data for dice 3: */
  131. USHORT chip dice3_data[]=
  132. {
  133.   0x0000,  /* 0000 0000 0000 0000   0 : Black  */
  134.   0x7800,  /* 0111 1000 0000 0000   1 : Orange */
  135.   0x7800,  /* 0111 1000 0000 0000              */
  136.   0x03C0,  /* 0000 0011 1100 0000              */
  137.   0x03C0,  /* 0000 0011 1100 0000              */
  138.   0x001E,  /* 0000 0000 0001 1110              */
  139.   0x001E,  /* 0000 0000 0001 1110              */
  140.   0x0000   /* 0000 0000 0000 0000              */
  141. };
  142.  
  143. /* Image structure for dice 3: */
  144. struct Image dice3=
  145. {
  146.   0,          /* LeftEdge, 0 pixels out. */
  147.   0,          /* TopEdge, 0 pixels down. */
  148.   16,         /* Width, 16 pixels wide. */
  149.   8,          /* Height, 8 lines heigh. */
  150.   1,          /* Depth, one Bitplane. */
  151.   dice3_data, /* ImageData, pointer to the image data. */
  152.   0x1,        /* PlanePick, affect Bitplane zero. */
  153.   0x2,        /* PlaneOnOff, fill Bitplane one with 1's. */
  154.   NULL        /* NextImage, no Image structure connected to this one. */
  155. };
  156.  
  157. /* The MenuItem structure for dice 3: */
  158. struct MenuItem my_dice3_item=
  159. {
  160.   &my_dice2_item,  /* NextItem, pointer to the next item in the list. */
  161.   0,               /* LeftEdge, 0 pixels out. */
  162.   30,              /* TopEdge, 30 lines down. */
  163.   50,              /* Width, 50 pixels wide. */
  164.   8,               /* Height, 8 lines high. */
  165.   ITEMENABLED|     /* Flags, this item will be enabled. */
  166.                    /*        render this item with an Image. */
  167.                    /*        (ITEMTEXT is not set.) */
  168.                    /*        it is an action item. */
  169.                    /*        (CHECKIT is not set.) */
  170.   HIGHCOMP,        /*        complement the colours when highlihted. */
  171.   0x00000000,      /* MutualExclude, no mutualexclude. */
  172.   (APTR) &dice3,   /* ItemFill, pointer to the image. */
  173.   NULL,            /* SelectFill, nothing since we complement the col. */
  174.   0,               /* Command, no command-key sequence. */
  175.   NULL,            /* SubItem, no subitem list. */
  176.   MENUNULL,        /* NextSelect, no items selected. */
  177. };
  178.  
  179.  
  180.  
  181. /*************************************************************************/
  182. /*                             D I C E   4                               */
  183. /*************************************************************************/
  184.  
  185. /* Data for dice 4: */
  186. USHORT chip dice4_data[]=
  187. {
  188.   0x0000,  /* 0000 0000 0000 0000   0 : Black  */
  189.   0x781E,  /* 0111 1000 0001 1110   1 : Orange */
  190.   0x781E,  /* 0111 1000 0001 1110              */
  191.   0x0000,  /* 0000 0000 0000 0000              */
  192.   0x0000,  /* 0000 0000 0000 0000              */
  193.   0x781E,  /* 0111 1000 0001 1110              */
  194.   0x781E,  /* 0111 1000 0001 1110              */
  195.   0x0000   /* 0000 0000 0000 0000              */
  196. };
  197.  
  198. /* Image structure for dice 4: */
  199. struct Image dice4=
  200. {
  201.   0,          /* LeftEdge, 0 pixels out. */
  202.   0,          /* TopEdge, 0 pixels down. */
  203.   16,         /* Width, 16 pixels wide. */
  204.   8,          /* Height, 8 lines heigh. */
  205.   1,          /* Depth, one Bitplane. */
  206.   dice4_data, /* ImageData, pointer to the image data. */
  207.   0x1,        /* PlanePick, affect Bitplane zero. */
  208.   0x2,        /* PlaneOnOff, fill Bitplane one with 1's. */
  209.   NULL        /* NextImage, no Image structure connected to this one. */
  210. };
  211.  
  212. /* The MenuItem structure for dice 4: */
  213. struct MenuItem my_dice4_item=
  214. {
  215.   &my_dice3_item,  /* NextItem, pointer to the next item in the list. */
  216.   0,               /* LeftEdge, 0 pixels out. */
  217.   20,              /* TopEdge, 20 lines down. */
  218.   50,              /* Width, 50 pixels wide. */
  219.   8,               /* Height, 8 lines high. */
  220.   ITEMENABLED|     /* Flags, this item will be enabled. */
  221.                    /*        render this item with an Image. */
  222.                    /*        (ITEMTEXT is not set.) */
  223.                    /*        it is an action item. */
  224.                    /*        (CHECKIT is not set.) */
  225.   HIGHCOMP,        /*        complement the colours when highlihted. */
  226.   0x00000000,      /* MutualExclude, no mutualexclude. */
  227.   (APTR) &dice4,   /* ItemFill, pointer to the image. */
  228.   NULL,            /* SelectFill, nothing since we complement the col. */
  229.   0,               /* Command, no command-key sequence. */
  230.   NULL,            /* SubItem, no subitem list. */
  231.   MENUNULL,        /* NextSelect, no items selected. */
  232. };
  233.  
  234.  
  235.  
  236. /*************************************************************************/
  237. /*                             D I C E   5                               */
  238. /*************************************************************************/
  239.  
  240. /* Data for dice 5: */
  241. USHORT chip dice5_data[]=
  242. {
  243.   0x0000,  /* 0000 0000 0000 0000   0 : Black  */
  244.   0x781E,  /* 0111 1000 0001 1110   1 : Orange */
  245.   0x781E,  /* 0111 1000 0001 1110              */
  246.   0x03C0,  /* 0000 0011 1100 0000              */
  247.   0x03C0,  /* 0000 0011 1100 0000              */
  248.   0x781E,  /* 0111 1000 0001 1110              */
  249.   0x781E,  /* 0111 1000 0001 1110              */
  250.   0x0000   /* 0000 0000 0000 0000              */
  251. };
  252.  
  253. /* Image structure for dice 5: */
  254. struct Image dice5=
  255. {
  256.   0,          /* LeftEdge, 0 pixels out. */
  257.   0,          /* TopEdge, 0 pixels down. */
  258.   16,         /* Width, 16 pixels wide. */
  259.   8,          /* Height, 8 lines heigh. */
  260.   1,          /* Depth, one Bitplane. */
  261.   dice5_data, /* ImageData, pointer to the image data. */
  262.   0x1,        /* PlanePick, affect Bitplane zero. */
  263.   0x2,        /* PlaneOnOff, fill Bitplane one with 1's. */
  264.   NULL        /* NextImage, no Image structure connected to this one. */
  265. };
  266.  
  267. /* The MenuItem structure for dice 5: */
  268. struct MenuItem my_dice5_item=
  269. {
  270.   &my_dice4_item,  /* NextItem, pointer to the next item in the list. */
  271.   0,               /* LeftEdge, 0 pixels out. */
  272.   10,              /* TopEdge, 10 lines down. */
  273.   50,              /* Width, 50 pixels wide. */
  274.   8,               /* Height, 8 lines high. */
  275.   ITEMENABLED|     /* Flags, this item will be enabled. */
  276.                    /*        render this item with an Image. */
  277.                    /*        (ITEMTEXT is not set.) */
  278.                    /*        it is an action item. */
  279.                    /*        (CHECKIT is not set.) */
  280.   HIGHCOMP,        /*        complement the colours when highlihted. */
  281.   0x00000000,      /* MutualExclude, no mutualexclude. */
  282.   (APTR) &dice5,   /* ItemFill, pointer to the image. */
  283.   NULL,            /* SelectFill, nothing since we complement the col. */
  284.   0,               /* Command, no command-key sequence. */
  285.   NULL,            /* SubItem, no subitem list. */
  286.   MENUNULL,        /* NextSelect, no items selected. */
  287. };
  288.  
  289.  
  290.  
  291. /*************************************************************************/
  292. /*                             D I C E   6                               */
  293. /*************************************************************************/
  294.  
  295. /* Data for dice 6: */
  296. USHORT chip dice6_data[]=
  297. {
  298.   0x0000,  /* 0000 0000 0000 0000   0 : Black  */
  299.   0x7BDE,  /* 0111 1011 1101 1110   1 : Orange */
  300.   0x7BDE,  /* 0111 1011 1101 1110              */
  301.   0x0000,  /* 0000 0000 0000 0000              */
  302.   0x0000,  /* 0000 0000 0000 0000              */
  303.   0x7BDE,  /* 0111 1011 1101 1110              */
  304.   0x7BDE,  /* 0111 1011 1101 1110              */
  305.   0x0000   /* 0000 0000 0000 0000              */
  306. };
  307.  
  308. /* Image structure for dice 6: */
  309. struct Image dice6=
  310. {
  311.   0,          /* LeftEdge, 0 pixels out. */
  312.   0,          /* TopEdge, 0 pixels down. */
  313.   16,         /* Width, 16 pixels wide. */
  314.   8,          /* Height, 8 lines heigh. */
  315.   1,          /* Depth, one Bitplane. */
  316.   dice6_data, /* ImageData, pointer to the image data. */
  317.   0x1,        /* PlanePick, affect Bitplane zero. */
  318.   0x2,        /* PlaneOnOff, fill Bitplane one with 1's. */
  319.   NULL        /* NextImage, no Image structure connected to this one. */
  320. };
  321.  
  322. /* The MenuItem structure for dice 6: */
  323. struct MenuItem my_dice6_item=
  324. {
  325.   &my_dice5_item,  /* NextItem, pointer to the next item in the list. */
  326.   0,               /* LeftEdge, 0 pixels out. */
  327.   0,               /* TopEdge, 0 lines down. */
  328.   50,              /* Width, 50 pixels wide. */
  329.   8,               /* Height, 8 lines high. */
  330.   ITEMENABLED|     /* Flags, this item will be enabled. */
  331.                    /*        render this item with an Image. */
  332.                    /*        (ITEMTEXT is not set.) */
  333.                    /*        it is an action item. */
  334.                    /*        (CHECKIT is not set.) */
  335.   HIGHCOMP,        /*        complement the colours when highlihted. */
  336.   0x00000000,      /* MutualExclude, no mutualexclude. */
  337.   (APTR) &dice6,   /* ItemFill, pointer to the image. */
  338.   NULL,            /* SelectFill, nothing since we complement the col. */
  339.   0,               /* Command, no command-key sequence. */
  340.   NULL,            /* SubItem, no subitem list. */
  341.   MENUNULL,        /* NextSelect, no items selected. */
  342. };
  343.  
  344.  
  345.  
  346. /*************************************************************************/
  347. /*                              M E N U                                  */
  348. /*************************************************************************/
  349.  
  350. /* The Menu structure for the first (and only) menu: */
  351. struct Menu my_menu=
  352. {
  353.   NULL,          /* NextMenu, no more menu structures. */
  354.   0,             /* LeftEdge, left corner. */
  355.   0,             /* TopEdge, for the moment ignored by Intuition. */
  356.   50,            /* Width, 50 pixels wide. */
  357.   0,             /* Height, for the moment ignored by Intuition. */
  358.   MENUENABLED,   /* Flags, this menu will be enabled. */
  359.   "Dice",        /* MenuName, the string. */
  360.   &my_dice6_item /* FirstItem, pointer to the first item in the list. */
  361. };
  362.  
  363.  
  364.  
  365. /* Declare a pointer to a Window structure: */ 
  366. struct Window *my_window;
  367.  
  368. /* Declare and initialize your NewWindow structure: */
  369. struct NewWindow my_new_window=
  370. {
  371.   50,            /* LeftEdge    x position of the window. */
  372.   25,            /* TopEdge     y positio of the window. */
  373.   200,           /* Width       200 pixels wide. */
  374.   100,           /* Height      100 lines high. */
  375.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  376.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  377.   CLOSEWINDOW|   /* IDCMPFlags  The window will give us a message if the */
  378.                  /*             user has selected the Close window gad. */
  379.   MENUPICK,
  380.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  381.   WINDOWCLOSE|   /*             Close Gadget. */
  382.   WINDOWDRAG|    /*             Drag gadget. */
  383.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  384.   WINDOWSIZING|  /*             Sizing Gadget. */
  385.   ACTIVATE,      /*             The window should be Active when opened. */
  386.   NULL,          /* FirstGadget No Custom gadgets. */
  387.   NULL,          /* CheckMark   Use Intuition's default checkmark. */
  388.   "GAME",        /* Title       Title of the window. */
  389.   NULL,          /* Screen      Connected to the Workbench Screen. */
  390.   NULL,          /* BitMap      No Custom BitMap. */
  391.   80,            /* MinWidth    We will not allow the window to become */
  392.   30,            /* MinHeight   smaller than 80 x 30, and not bigger */
  393.   300,           /* MaxWidth    than 300 x 200. */
  394.   200,           /* MaxHeight */
  395.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  396. };
  397.  
  398.  
  399.  
  400. main()
  401. {
  402.   /* Boolean variable used for the while loop: */
  403.   BOOL close_me;
  404.  
  405.   /* Declare a variable in which we will store the IDCMP flag: */
  406.   ULONG class;
  407.   
  408.   /* If we recieve a MENUPICK event, the Code field of the message */
  409.   /* structure will contain the menu number of the first selected item. */
  410.   /* Declare a variable to store the Code value in, and an extra menu */
  411.   /* number variable: */
  412.   USHORT code, menu_number;
  413.   
  414.   /* Declare a MenuItem pointer: */
  415.   struct MenuItem *item;
  416.   
  417.   /* Declare a pointer to an IntuiMessage structure: */
  418.   struct IntuiMessage *my_message;
  419.  
  420.  
  421.  
  422.   /* Before we can use Intuition we need to open the Intuition Library: */
  423.   IntuitionBase = (struct IntuitionBase *)
  424.     OpenLibrary( "intuition.library", 0 );
  425.   
  426.   if( IntuitionBase == NULL )
  427.     exit(); /* Could NOT open the Intuition Library! */
  428.  
  429.  
  430.  
  431.   /* We will now try to open the window: */
  432.   my_window = (struct Window *) OpenWindow( &my_new_window );
  433.   
  434.   /* Have we opened the window succesfully? */
  435.   if(my_window == NULL)
  436.   {
  437.     /* Could NOT open the Window! */
  438.     
  439.     /* Close the Intuition Library since we have opened it: */
  440.     CloseLibrary( IntuitionBase );
  441.  
  442.     exit();  
  443.   }
  444.  
  445.  
  446.  
  447.   /* We have opened the window, and everything seems to be OK. */
  448.  
  449.  
  450.  
  451.   SetMenuStrip( my_window, &my_menu );
  452.   printf("Menustrip connected to window!\n");
  453.  
  454.  
  455.   close_me = FALSE;
  456.  
  457.   /* Stay in the while loop until the user has selected the Close window */
  458.   /* gadget: */
  459.   while( close_me == FALSE )
  460.   {
  461.     /* Wait until we have recieved a message: */
  462.     Wait( 1 << my_window->UserPort->mp_SigBit );
  463.  
  464.     /* As long as we collect messages sucessfully we stay in the loop: */
  465.     while(my_message=(struct IntuiMessage *) GetMsg( my_window->UserPort ))
  466.     {
  467.       /* After we have collected the message we can read it, and save any */
  468.       /* important values which we maybe want to check later: */
  469.       class = my_message->Class;
  470.       code = my_message->Code;
  471.  
  472.  
  473.       /* After we have read it we reply as fast as possible: */
  474.       /* REMEMBER! Do never try to read a message after you have replied! */
  475.       /* Some other process has maybe changed it. */
  476.       ReplyMsg( my_message );
  477.  
  478.       /* Check which IDCMP flag was sent: */
  479.       if( class == CLOSEWINDOW )
  480.         close_me=TRUE; /* The user selected the Close window gadget! */  
  481.  
  482.       if(class == MENUPICK)
  483.       {
  484.         printf("\nMenu pick!\n");
  485.         menu_number = code;
  486.         
  487.         while( menu_number != MENUNULL )
  488.         {
  489.           /* Get the address of the item: */
  490.           item = (struct MenuItem *) ItemAddress( &my_menu, menu_number );
  491.  
  492.  
  493.           /* Print out the menu number plus etc: */
  494.           printf("menu_number= %d\n", menu_number );
  495.           printf("MENUNUM = %d\n", MENUNUM(menu_number) );
  496.           printf("ITEMNUM = %d\n", ITEMNUM(menu_number) );
  497.           printf("SUBNUM  = %d\n", SUBNUM(menu_number) );
  498.  
  499.  
  500.           /* Get the following item's menu number: */
  501.           menu_number = item->NextSelect;
  502.         }
  503.       }
  504.     }
  505.   }
  506.  
  507.  
  508.  
  509.   printf("Menustrip removed from window!\n");
  510.   ClearMenuStrip( my_window );
  511.  
  512.  
  513.  
  514.   /* Close the window: */
  515.   CloseWindow( my_window );
  516.  
  517.  
  518.  
  519.   /* Close the Intuition Library since we have opened it: */
  520.   CloseLibrary( IntuitionBase );
  521.   
  522.   /* THE END */
  523. }
  524.